package com.maistars.spider.service.store;

import com.maistars.spider.service.domain.store.TaskStoreConfig;
import com.maistars.spider.service.domain.task.CrawlerTaskInst;
import com.maistars.spider.service.store.local.LocalCapturedPageStore;
import com.maistars.spider.common.constants.StoreType;
import com.maistars.spider.service.store.console.ConsoleCapturedPageStore;
import com.maistars.spider.service.store.console.ConsoleExtractedFieldStore;
import lombok.Getter;

/**
 * @author dhr
 * @date 2021/9/5 下午11:38
 */
public class TaskInstResultStore {

    @Getter
    private CrawlerTaskInst crawlerTaskInst;

    @Getter
    private CapturedPageStore capturedPageStore;

    @Getter
    private ExtractedFieldStore extractedFieldStore;

    public TaskInstResultStore(CrawlerTaskInst crawlerTaskInst){
        this.crawlerTaskInst = crawlerTaskInst;
    }

    public void init(){
        // 解析StoreConfig
        TaskStoreConfig taskStoreConfig = crawlerTaskInst.getTaskStoreConfig();
        if(StoreType.LOCAL.getValue() == taskStoreConfig.getCapturedPageStoreType()){
            capturedPageStore = new LocalCapturedPageStore();

        }else if(StoreType.CONSOLE.getValue() == taskStoreConfig.getCapturedPageStoreType()){
            capturedPageStore = new ConsoleCapturedPageStore(crawlerTaskInst.getTaskInstId());
            extractedFieldStore = new ConsoleExtractedFieldStore(crawlerTaskInst.getTaskInstId());
        }
    }

}
